from flightanalysis.schedule import Schedule, Manoeuvre, rollmaker, reboundrollmaker, rollsnapcombomaker
from flightanalysis.schedule.elements import Loop, Line, Snap, Snap, Spin, StallTurn
from flightanalysis.schedule.figure_rules import Categories, IMAC, F3ACentre, F3AEnd,F3AEndB
from flightplotting.plots import plotsec
from flightplotting.traces import boxtrace
import plotly.graph_objects as go
from geometry import Transformation
import numpy as np
import plotly
plotly.offline.init_notebook_mode()
boxscale = 170 * np.tan(np.radians(60))
def plot_manoeuvre(itran: Transformation, man: Manoeuvre, scale=boxscale, speed=40, show=True):
template = man.scale(scale).create_template(itran, speed)
if show:
fig = plotsec(template, scale=10, nmodels=3)
fig = go.Figure(data = fig.data, layout = go.Layout(template="plotly+flight3d+judge_view"))
#fig.xaxes(range=[0, 200])
fig.update_layout(width=1200)
fig.show()
man_end = template[-1].transform
print("min z ={:.4f}, max z = {:.4f}".format(template.z.min() / scale, template.z.max() / scale))
print("final x={:.4f}, final z={:.4f}".format(man_end.translation.x / scale, man_end.translation.z / scale))
return man_end
mans = [None for _ in range(18)]
mends = [None for _ in range(18)]
schedule = Schedule("P23", Categories.F3A, "upright", -1, 0.1, [])
itrans = schedule.scale_distance(170.0).create_itransform("left", 170.0)
print("final x={}, final z={}".format(itrans.translation.x, itrans.translation.z))
final x=294.4486372867091, final z=29.44486372867091
i = 1
mans[i-1] = Manoeuvre("tophat", 4, [
Line(0.5, 0.0),
Loop( 0.3, -0.25),
] + rollmaker(2, "X", 4, 0.4, "Centre") + [
Loop( 0.3, -0.25),
] + rollmaker(1, "/", 2, 0.4, "Centre") + [
Loop( 0.3, 0.25),
] + rollmaker(2, "X", 4, 0.4, "Centre") + [
Loop( 0.3, 0.25) # 0.5
], F3ACentre, i)
mends[i] = plot_manoeuvre(itrans, mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.8000 final x=-0.5000, final z=0.1000
i=2
mans[i-1] = Manoeuvre("hsq", 2, [
Line(0.2, 0.0),
Loop( 0.3, 0.25),
] + rollmaker(1, "/", 2, 0.6, "Centre") + [
Loop( 0.3, -0.25),
], F3AEnd, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 1.0000 final x=-0.7000, final z=1.0000
i=3
mans[i-1] = Manoeuvre("hump", 4, [
Line(0.7, 0.0),
Loop( 0.3, -0.25),
] + reboundrollmaker([-1.0], 0.6, "Centre") + [
Loop( 0.3, -0.5),
] + rollmaker(1, "/", 2, 0.6, "Centre") + [
Loop( 0.3, 0.25),
], F3ACentre, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 1.0000 final x=-0.0000, final z=1.0000
i=4
c45 = np.cos(np.radians(45))
mans[i-1] = Manoeuvre("hsc", 3, [
Line(0.5, 0.0),
Loop( 0.4, 0.125),
] + rollmaker(1, "/", 2, 0.25 / c45, "Centre") + [
Loop( 0.4, -0.25),
] + rollmaker(1, "/", 2, 0.25 / c45, "Centre") + [
Loop( 0.4, 0.125), # 0.5, h=0.2
], F3AEnd, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 1.0000 final x=0.5000, final z=0.1000
i=5
mans[i-1] = Manoeuvre("u45", 5, [
Line(0.07378332134514629, 0.0, 0.0),
Loop( 0.3, 0.125),
Line(0.4 + 0.003924442635585339, 0.0),
Snap(1.5, negative=True),
Line(0.4 + 0.003924442635585339, 0.0),
Loop(0.3, 0.125),
], F3ACentre, i-1)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.8316 final x=-0.4296, final z=0.8316
i=6
mans[i-1] = Manoeuvre("h8l", 3, [
Line(0.28024080245320503, 0.0),
Loop(0.3, 0.125),
Line(0.16, 0.0),
Loop(0.3, 0.125),
Line(0.16, 0.0),
Loop(0.3, 0.125),
Line(0.16, 0.0),
Loop(0.3, 0.125), # 0.7
], F3AEnd, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1453, max z = 0.8316 final x=-0.7099, final z=0.1453
i=7
mans[i-1] = Manoeuvre("rc", 4, [
Line(0.25, 0.0), # 0.4
Line(0.2, 0.5), # 0.2
Line(0.05, 0.0),
Line(0.2, 0.5),
Line(0.2, -0.5),
Line(0.05, 0.0),
Line(0.2, -0.5, 0.0), # 0.45
], F3ACentre, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1453, max z = 0.1453 final x=0.4401, final z=0.1453
i=8
mans[7] = Manoeuvre("imm", 2, [
Line(0.15, 0.0), # 0.6
Loop( 0.697365440327093, 0.5), # h=0.8
Line(0.2, 0.5), # 0.4
], F3AEnd, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1453, max z = 0.8427 final x=0.3901, final z=0.8427
i=9
mans[8] = Manoeuvre("spin", 4, [
Line(0.39320764389188684, 0.0, 0.0),
Spin(2.5),
Line(0.3491980890270279, 0.0),
Loop( 0.3, -0.25), # 0.15, h=0.1
], F3ACentre, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[8], speed=30.0, show=True)
min z =0.1000, max z = 0.8427 final x=-0.1531, final z=0.1000
i=10
mans[i-1] = Manoeuvre("hB", 3, [
Line(0.35, 0.0), # 0.5
Loop( 0.3, -0.25), # 0.65
] + rollmaker(1, "/", 2, 0.5, "Centre") + [
Loop( 0.3, -0.5), # 0.95
] + rollmaker(1, "/", 2, 0.5, "Centre") + [
Loop( 0.3, 0.25), # 0.8
], F3AEnd, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.9000 final x=-0.8031, final z=0.1000
i=11
mans[i-1] = Manoeuvre("Et", 4, [
Line(0.3428932188134527, 0.0), # 0.5
Loop( 0.5, 0.125), # 0.65
] + reboundrollmaker([0.5, -0.5], 0.5, "Centre") + [
Loop( 0.5, -7/8), # 0.95
] + rollmaker(2, "X", 4, 0.3, "Centre") + [
Loop( 0.5, 0.25), # -0.18366018118654734, 0.9
], F3ACentre, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.9000 final x=0.2469, final z=0.9000
i=12
mans[i-1] = Manoeuvre("hsq2", 2, [
Line(0.35, 0.0), # 0.6
Loop( 0.3, 0.25), # 0.65, 0.85
] + rollmaker(1, "/", 2, 0.5, "Centre") + [ # 0.25
Loop( 0.3, -0.25), # 0.6 , 0.1
], F3AEnd, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.9000 final x=0.5969, final z=0.1000
i=13
mans[i-1] = Manoeuvre("figM", 5, [
Line(0.45, 0.0), # 0.15
Loop( 0.3, -0.25),
] + reboundrollmaker([-0.75], 0.5, "Centre") + [
StallTurn(),
Line(0.5, 0.0), # 0.15
Loop( 0.3, 0.5),
Line(0.5, 0.0), # 0.15
StallTurn(),
] + reboundrollmaker([-0.75], 0.5, "Centre") + [
Loop( 0.3, -0.25), # 0.15
], F3ACentre, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.7500 final x=-0.1531, final z=0.1000
i=14
mans[i-1] = Manoeuvre("fight", 2, [
Line(0.2, 0.0), # 0.25
Loop( 0.3, -0.125),
] + reboundrollmaker([-0.25], 0.4, "Centre") + [
Loop( 0.3, 0.5),
] + reboundrollmaker([0.25], 0.4, "Centre") + [
Loop( 0.3, -0.125), # 0.35
], F3AEndB, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.5328 final x=-0.3531, final z=0.1000
i=15
mans[i-1] = Manoeuvre("tri", 2, [
Line(0.25, 0.0), # 0.1
Line(0.2, 0.5), #0.1
Line(0.3, 0.0), #0.4
Loop( 0.3, 0.375), #0.4
] + rollmaker(2, "X", 4, 0.4/c45, "Centre") + [
Loop( 0.3, -0.25), #0.4
] + rollmaker(2, "X", 4, 0.4/c45, "Centre") + [
Loop( 0.3, 0.375), #0.4
Line(0.3, 0.0), #0.4
Line(0.2, 0.5), #0.1
], F3ACentre, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.8000 final x=0.0969, final z=0.1000
i=16
mans[i-1] = Manoeuvre("shark", 2, [
Line(0.75, 0.0), # 0.9
Loop( 0.3, -0.25), #0.4
] + rollmaker(1, "/", 2, 0.25, "Centre") + [
Loop( 0.3, 0.375), #0.4
] + rollmaker(2, "X", 4, (0.25 + 0.3 * c45) / c45, "Centre") + [
Loop( 0.3, 0.125), #-0.17573593128807238
], F3AEndB, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.6500 final x=0.1726, final z=0.1000
i=17
mans[i-1] = Manoeuvre("loop", 2, [
Line(0.17573593128807238, 0.0, 0.0), # 0.0
Loop( 0.7, 0.375), #0.4
Loop( 0.7, 0.25, 0.5), #0.4
Loop( 0.7, -0.375), #0.4
], F3ACentre, i)
mends[i] = plot_manoeuvre(mends[i-1], mans[i-1], speed=30.0, show=True)
min z =0.1000, max z = 0.8000 final x=-0.0031, final z=0.1000
mans[17] = Manoeuvre("Landing", 1, [Line(0.5)], uid=18)
schedule.manoeuvres = mans
sched = schedule.scale_distance(170)
template = sched.create_raw_template("right", 30.0, 170, True)
from flightplotting.plots import plotdtw
fig = plotdtw(template, sched.manoeuvres)
fig.update_layout(width=800)
#fig.add_traces(boxtrace())
fig.show()
from flightanalysis import FCJson, Box
from flightdata import Flight
import numpy as np
import pandas as pd
from json import dump
with open("flightanalysis/data/P23.json", "w") as f:
dump(schedule.to_dict(), f)
fcj = FCJson("P23", None, None, template, sched )
data = fcj.create_fc_json()
from json import dump
with open("P23_template.json", "w") as f:
dump(data, f)
/home/tom/source/PyFlightCoach/geometry/geometry/quaternions.py:158: RuntimeWarning: invalid value encountered in arcsin